package leetcode;

import java.util.Scanner;

/**
 * 非法invalid input
 * 2000-2-28
 * 2001-2-29
 * 2000-2-28 is the No.59 day of 2000.
 *
 */

public class SingleNumberTwo {
    public static void main(String[] args) {
        final int[] monthEnum = {31,28,31,30,31,30,31,31,30,31,30,31};
        System.out.println("please input the year!");
        Scanner sc = new Scanner(System.in);

        String string = sc.nextLine();
        String[] temp = string.split("-");
        int year = Integer.parseInt(temp[0]);
        int month = Integer.parseInt(temp[1]);
        int day = Integer.parseInt(temp[2]);
        //System.out.println(checkLeapYear(year));
        if (year<=0||day<=0||month<=0){
            System.out.println("invalid input");
            return;
        }
        if (checkLeapYear(year)&&month==2&&day>29){
            System.out.println("invalid input");
            return;
        }
        if ((!checkLeapYear(year))&&month==2&&day>28){
            System.out.println("invalid input");
            return;
        }
        if(day>monthEnum[month+1]||month>12||year>10000){
            System.out.println("invalid input");
            return;
        }

        if(month>2){
            int tempDay = 0;
            for (int i = 0; i < month; i++) {
                tempDay+=monthEnum[i];
            }
            if (!checkLeapYear(year)){
                //2000-2-28 is the No.59 day of 2000.
                System.out.println(string+" "+"is the No."+tempDay+" day of "+year);
            }else{
                System.out.println(string+" "+"is the No."+(tempDay+1)+" day of "+year);
            }
        }else{
            if(month==1){
                System.out.println(string+" "+"is the No."+day+" day of "+year);
            }else {
                System.out.println(string+" "+"is the No."+(monthEnum[0]+day)+" day of "+year);
            }

        }





    }
    public static boolean checkLeapYear(int year){
        boolean flag=false;
        if((year%4 == 0) && ((year%100 != 0) || (year%400 == 0))){
            flag=true;
        }
        return flag;
    }

}




